//
//  UIViewController+CYGPushedNaviBar.m
//  CYGHuntForCity
//
//  Created by cygarm on 16/3/17.
//  Copyright © 2016年 cygarm. All rights reserved.
//

#import "UIViewController+CYGPushedNaviBar.h"
#import "CYGDoubleTitleView.h"

UIColor *cyg_pushedSrcBarColor;

@implementation UIViewController (CYGPushedNaviBar)

- (void)cyg_initPushedNavigationBarWithBackgroundColor:(UIColor *)backColor titile:(NSString *)title subTitle:(NSString *)subTitle {	
	if (backColor == nil ||
		CGColorEqualToColor(self.navigationController.navigationBar.barTintColor.CGColor, 
							backColor.CGColor)) {
		cyg_pushedSrcBarColor = nil;
	} else {
		cyg_pushedSrcBarColor = self.navigationController.navigationBar.barTintColor;
		self.navigationController.navigationBar.barTintColor = backColor;
	}
	
	self.navigationItem.hidesBackButton = YES;
	self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(cyg_pushedBackBtnClick:)];
	self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_share_normal"] style:UIBarButtonItemStylePlain target:self action:@selector(cyg_pushedShareBtnClick:)];
//	self.navigationItem.leftBarButtonItem.imageInsets = UIEdgeInsetsMake(4, 4, 4, 4);
//	self.navigationItem.rightBarButtonItem.imageInsets = UIEdgeInsetsMake(5, 5, 5, 5);
	
	CYGDoubleTitleView *titleView = [[CYGDoubleTitleView alloc] initWithFrame:CGRectMake(0, 0, CYGAppWidth, 64)];
	titleView.title.text = title;
	titleView.subTitle.text = subTitle;
	self.navigationItem.titleView = titleView;
}

- (UIView *)cyg_customPushedNavigationBarWithBackgroundColor:(UIColor *)backColor titile:(NSString *)title subTitle:(NSString *)subTitle {
	CYGDoubleTitleView *bar = [[CYGDoubleTitleView alloc] initWithFrame:CGRectMake(0, 0, CYGAppWidth, 64)];
	bar.backgroundColor = backColor;
	bar.noStatusBar = YES;
	bar.title.text = title;
	bar.subTitle.text = subTitle;
	
	UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(5, 6+20, 52, 30)];
	[leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
	[leftBtn addTarget:self action:@selector(cyg_pushedBackBtnClick:) forControlEvents:UIControlEventTouchUpInside];
	UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(267, 6+20, 58, 30)];
	[rightBtn setImage:[UIImage imageNamed:@"btn_share_normal"] forState:UIControlStateNormal];
	[rightBtn addTarget:self action:@selector(cyg_pushedShareBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//	leftBtn.imageEdgeInsets = UIEdgeInsetsMake(4, 4, 4, 4);
//	rightBtn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
	
	[bar addSubview:leftBtn];
	[bar addSubview:rightBtn];
	
	return bar;
}

- (void)cyg_pushedBackBtnClick:(id)sender {
	if (cyg_pushedSrcBarColor) {
		self.navigationController.navigationBar.barTintColor = cyg_pushedSrcBarColor;
	}
	[self.navigationController popViewControllerAnimated:YES];
}

- (void)cyg_pushedShareBtnClick:(id)sender {
	
}


@end
